package com.base.cn.platform.os.service.manage.teacher;

import com.base.cn.platform.os.common.mybatis.BaseBiz;
import com.base.cn.platform.os.common.mybatis.BaseEntity;
import com.base.cn.platform.os.common.mybatis.Pagination;
import com.base.cn.platform.os.common.service.CommonSetSubjectDataService;
import com.base.cn.platform.os.common.utils.DataUtil;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.common.utils.course.CourseType;
import com.base.cn.platform.os.dao.manage.teacher.SysTeacherDao;
import com.base.cn.platform.os.entity.manage.subject.SysSubject;
import com.base.cn.platform.os.entity.manage.teacher.SysTeacher;
import com.base.cn.platform.os.entity.manage.teacher.SysTeacherCondition;
import com.base.cn.platform.os.entity.manage.teacher.TeacherExpand;
import com.base.cn.platform.os.entity.manage.user.SysUser;
import com.base.cn.platform.os.service.course.cou.CourseService;
import com.base.cn.platform.os.service.course.qa.qatype.QaTypeService;
import com.base.cn.platform.os.service.course.qa.record.QaTeacherCommissionService;
import com.base.cn.platform.os.service.manage.subject.SysSubjectBiz;
import com.base.cn.platform.os.service.manage.user.SysUserBiz;
import com.base.cn.platform.os.service.op.groom.OpGroomDataBiz;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 讲师的业务Biz
 *
 * @author s.li
 * @create 2018-04-08-14:45
 */
@Service
public class SysTeacherBiz extends BaseBiz<SysTeacher,SysTeacherDao> {
    @Autowired
    private SysSubjectBiz sysSubjectBiz;
    @Autowired
    private SysUserBiz sysUserBiz;
    @Autowired
    private CommonSetSubjectDataService<SysTeacher> commonSetSubjectDataService;
    @Autowired
    private CourseService courseService;
    @Autowired
    private QaTypeService qaTypeService;
    @Autowired
    private OpGroomDataBiz opGroomDataBiz;
    @Autowired
    private QaTeacherCommissionService  qaTeacherCommissionService;

    /**
     * 查询讲师数量
     * @param condition 查询条件
     * @return 数量
     */
    public BigDecimal getCount(SysTeacherCondition condition) {
        return this.count(this.getWhereSql(condition));
    }

    /**
     * 创建用户关联的讲师数据
     * @param sysUser 用户数据对象
     * @return BigDecimal 讲师ID
     */
    public BigDecimal sysSysUserToTeacher(SysUser sysUser){
        SysTeacher sysTeacher = new SysTeacher();
        sysTeacher.setTeacherName(sysUser.getRalName());
        sysTeacher.setImageJson(sysUser.getImageJson());
        sysTeacher.setSysUserId(sysUser.getId());
        sysTeacher.setTeacherType(1);
        sysTeacher.setIsQuestion(0);
        sysTeacher.setCreateUserId(sysUser.getCreateUserId());
        this.saveSysTeacher(sysTeacher);
        return sysTeacher.getId();
    }

    /**
     * 保存讲师
     * @param sysTeacher 讲师数据对象
     * @return SysTeacher
     */
    @Transactional(rollbackFor =  IllegalArgumentException.class)
    public SysTeacher saveSysTeacher(SysTeacher sysTeacher){
        BigDecimal newQaTypeId = sysTeacher.getQaTypeId();
        BigDecimal oldQaTypeId = new BigDecimal(0);
        //修改
        if(DataUtil.idIsNotNull(sysTeacher.getId())){
            SysTeacher _sysTeacher = this.findById(sysTeacher.getId());
            //原来关联的问答分类
            oldQaTypeId = _sysTeacher.getQaTypeId();
            //原关联的用户ID
            BigDecimal _sysUserId = _sysTeacher.getSysUserId();
            //现关联的用户ID
            BigDecimal sysUserId = sysTeacher.getSysUserId();
            _sysTeacher.setTeacherName(sysTeacher.getTeacherName());
            _sysTeacher.setSubjectIds(sysTeacher.getSubjectIds());
            _sysTeacher.setSysUserId(sysTeacher.getSysUserId());
            _sysTeacher.setImageJson(sysTeacher.getImageJson());
            _sysTeacher.setDepict(sysTeacher.getDepict());
            _sysTeacher.setTeacherType(sysTeacher.getTeacherType());
            _sysTeacher.setIsQuestion(sysTeacher.getIsQuestion());
            _sysTeacher.setQaTypeId(DataUtil.idIsNotNull(sysTeacher.getQaTypeId())?sysTeacher.getQaTypeId(): new BigDecimal(0));
            _sysTeacher.setQuestionFee(sysTeacher.getQuestionFee());
            _sysTeacher.setSeparateInto(sysTeacher.getSeparateInto());
            _sysTeacher.setSort(sysTeacher.getSort());
            _sysTeacher.setQuestionNum(sysTeacher.getQuestionNum());
            _sysTeacher.setUserNum(sysTeacher.getUserNum());
            _sysTeacher.setCourseNum(sysTeacher.getCourseNum());
            _sysTeacher.setTeacherIdentity(sysTeacher.getTeacherIdentity());
            if(_sysTeacher.getStatus().intValue()==0){
                _sysTeacher.setStatus(1);
            }
            this.updateById(_sysTeacher,null);
            SysUser sysUser =new SysUser();
            //原来没有关联过用户，现在关联了，则去更新现在关联的用户的讲师ID
            if(!DataUtil.idIsNotNull(_sysUserId) && DataUtil.idIsNotNull(sysUserId)){
                sysUser.setTeacherId(_sysTeacher.getId());//把未关联讲师的用户关联上讲师
                sysUserBiz.updateByWhereSql(sysUser," id="+sysUserId);
            }else if(DataUtil.idIsNotNull(_sysUserId) && (!DataUtil.idIsNotNull(sysUserId) || _sysUserId.compareTo(sysUserId)!=0)){
                //如果原来关联过用户，现在不关联或关联的和原来关联用户不是同一个，则清空原来关联的用户讲师ID
                sysUser.setTeacherId(new BigDecimal(0));//把原来关联用户的讲师ID设置0
                sysUserBiz.updateByWhereSql(sysUser," id="+_sysUserId);
                //现选择的用户的关联当前修改的讲师
                if(DataUtil.idIsNotNull(sysUserId) && _sysUserId.compareTo(sysUserId)!=0){
                    sysUser.setTeacherId(_sysTeacher.getId());
                    sysUserBiz.updateByWhereSql(sysUser," id="+sysUserId);
                }
            }
        }else {//添加
            this.save(sysTeacher);
            if(DataUtil.idIsNotNull(sysTeacher.getSysUserId())){
                SysUser sysUser = new SysUser();
                sysUser.setTeacherId(sysTeacher.getId());//把未关联讲师的用户关联上讲师
                sysUserBiz.updateByWhereSql(sysUser," id="+sysTeacher.getSysUserId());
            }
        }
        qaTypeService.updateTeacherNum(newQaTypeId, oldQaTypeId);
        return sysTeacher;
    }

    /**
     * 通过ID串获取讲师列表
     * @param teacherId
     * @param subjectData 是否查询专业数据，true是，false否
     * @param createUser 是否查询创建人数据，true是，false否
     * @param sysUserData 是否查询关联用户数据，true是，false否
     * @param courseData 是否查询关联课程数据，true是，false否
     * @param qaTypeData 是否查询关联问答分类，true是，false否
     * @return SysTeacher
     */
    public SysTeacher findSysTeacherById(BigDecimal teacherId,boolean subjectData,boolean createUser,boolean sysUserData, boolean courseData, boolean qaTypeData){
        SysTeacher sysTeacher = this.findById(teacherId);
        if(sysTeacher !=null){
            this.setSysTeacherSubject(sysTeacher,subjectData);
            this.setSysTeacherSysUser(sysTeacher,createUser,sysUserData);
            this.setSysTeacherCourse(sysTeacher, courseData);
            this.setSysTeacherQaType(sysTeacher, qaTypeData);
        }
        return sysTeacher;
    }

    /**
     * 通过ID串获取讲师Map集合
     * @param ids 讲师ID
     * @param subjectData 是否查询专业数据，true是，false否
     * @param createUser 是否查询创建人数据，true是，false否
     * @param sysUserData 是否查询关联用户数据，true是，false否
     * @param courseData 是否查询关联课程数据，true是，false否
     * @param qaTypeData 是否查询关联问答数据，true是，false否
     * @return Map<BigDecimal,SysTeacher>
     */
    public Map<BigDecimal,SysTeacher> findSysTeacherToMapByIds(String ids, boolean subjectData, boolean createUser, boolean sysUserData, boolean courseData, boolean qaTypeData) {
        List<SysTeacher> sysTeacherList = this.findSysTeacherByIds(ids,subjectData,createUser,sysUserData, courseData, qaTypeData);
        if(ObjectUtils.isNotEmpty(sysTeacherList)){
            return sysTeacherList.stream().collect(Collectors.toMap(BaseEntity::getId, e->e));
        }
        return null;
    }

    /**
     * 通过ID串获取讲师列表
     * @param ids 讲师ID
     * @param subjectData
     * @param createUser
     * @param sysUserData
     * @param courseData
     * @return List<SysTeacher>
     */
    public List<SysTeacher> findSysTeacherByIds(String ids,boolean subjectData,boolean createUser,boolean sysUserData, boolean courseData, boolean qaTypeData){
        SysTeacherCondition condition = new SysTeacherCondition();
        condition.setIds(ids);
        return this.findSysTeacherList(condition,subjectData,createUser,sysUserData, courseData, qaTypeData);
    }

    /**
     * 多条件查询讲师列表
     * @param condition
     * @param subjectData
     * @param createUser
     * @param sysUserData
     * @param courseData
     * @return
     */
    public List<SysTeacher> findSysTeacherList(SysTeacherCondition condition,boolean subjectData,boolean createUser,boolean sysUserData, boolean courseData, boolean qaTypeData){
        String whereSql = getWhereSql(condition);
        List<SysTeacher> sysTeacherList = this.find(whereSql,null,null);
        sysTeacherList = this.setSysTeacherSubject(sysTeacherList,subjectData);
        sysTeacherList = this.setSysTeacherSysUser(sysTeacherList,createUser,sysUserData);
        sysTeacherList = this.setSysTeacherCourse(sysTeacherList, courseData);
        sysTeacherList = this.setSysTeacherQaType(sysTeacherList, qaTypeData);
        return sysTeacherList;
    }

    /**
     * 颁布查询讲师列表
     * @param condition
     * @param page
     * @param subjectData
     * @param createUser
     * @param sysUserData
     * @return PageInfo<SysTeacher>
     */
    public PageInfo<SysTeacher> findSysTeacherList(SysTeacherCondition condition ,
                                                   Pagination page,
                                                   boolean subjectData,boolean createUser,boolean sysUserData){
        String whereSql = getWhereSql(condition);
        PageInfo<SysTeacher> sysTeacherPageInfo = this.findPage(whereSql,page,null);
        List<SysTeacher> sysTeacherList = sysTeacherPageInfo.getList();
        sysTeacherList = this.setSysTeacherSubject(sysTeacherList,subjectData);
        sysTeacherList = this.setSysTeacherSysUser(sysTeacherList,createUser,sysUserData);
        sysTeacherPageInfo.setList(sysTeacherList);
        return sysTeacherPageInfo;
    }

    /**
     * 修改讲师状态
     * @param ids 讲师ID串
     * @param status 状态，1正常，2禁用，3删除
     */
    public void updateSysTeacherStatus(String ids,int status){
        if(StringUtils.isNotEmpty(ids)){
            ids = StringUtils.subHeadTailString(ids,",");
            if(StringUtils.isNotEmpty(ids)){
                SysTeacher sysTeacher = new SysTeacher();
                sysTeacher.setStatus(status);
                this.updateByWhereSql(sysTeacher," id in ("+ids+")");
                if(status==2 || status==3){
                    opGroomDataBiz.deleteGroomDataByDataIdAndDataType(ids,"TEACHER");
                }
            }
        }
    }

    /**
     * 根据sql语句查询讲师集合
     * @param whereSql 查询语句
     * @param subjectData 是否查询专业数据，true是，false否
     * @param createUser 是否查询创建人数据，true是，false否
     * @param sysUserData 是否查询关联用户数据，true是，false否
     * @return teacherMap集合
     */
    public List<SysTeacher> findTeacherMapList(String whereSql, boolean subjectData, boolean createUser, boolean sysUserData){
        if(StringUtils.isNotEmpty(whereSql) && StringUtils.isNotEmpty(whereSql.trim())){
            List<SysTeacher> sysTeacherList = this.find(whereSql, null, this.getColumnName());
            if(ObjectUtils.isNotEmpty(sysTeacherList)){
                sysTeacherList = this.setSysTeacherSubject(sysTeacherList, subjectData);
                sysTeacherList = this.setSysTeacherSysUser(sysTeacherList, createUser, sysUserData);
            }
            return sysTeacherList;
        }
        return null;
    }

    /**
     * 根据sql查询讲师ID及讲师名称的集合
     * @param whereSql 查询语句
     * @param subjectData 是否查询专业数据，true是，false否
     * @param createUser 是否查询创建人数据，true是，false否
     * @param sysUserData 是否查询关联用户数据，true是，false否
     * @return
     */
    public Map<BigDecimal,String> findTeacherToMapList(String whereSql, boolean subjectData, boolean createUser, boolean sysUserData){
        if(StringUtils.isNotEmpty(whereSql) && StringUtils.isNotEmpty(whereSql.trim())) {
            List<SysTeacher> sysTeacherList = this.find(whereSql, null, this.getColumnName());
            if (ObjectUtils.isNotEmpty(sysTeacherList)) {
                Map<BigDecimal,String> teacherMap = new HashMap<>();
                for(int i=0;i<sysTeacherList.size();i++){
                    SysTeacher sysTeacher = sysTeacherList.get(i);
                    teacherMap.put(sysTeacher.getId(),sysTeacher.getTeacherName());
                }
                return teacherMap;
            }
        }
        return null;
    }


    /**
     * 颁布查询讲师列表
     * @param condition
     * @param page
     * @return PageInfo<SysTeacher>
     */
    public PageInfo<SysTeacher> findSysTeacherCommissionListPage(SysTeacherCondition condition ,
                                                                 Pagination page){

        PageInfo<SysTeacher> sysTeacherList = findSysTeacherList(condition, page, false, false, false);
        //设置讲师收益
        for(SysTeacher sysTeacher:sysTeacherList.getList()){
            List<TeacherExpand> teacherExpands = qaTeacherCommissionService.qaTeacherCommissionSum(sysTeacher.getId());
            sysTeacher.setExpand(teacherExpands);
        }
        return sysTeacherList;
    }

    //========================================================

    private String getWhereSql(SysTeacherCondition condition){
        StringBuilder whereSql = new StringBuilder("status!=3");
        if(ObjectUtils.isNotEmpty(condition)){
            if(StringUtils.isNotEmpty(condition.getIds())){
                String ids = StringUtils.subHeadTailString(condition.getIds(),",");
                if(StringUtils.isNotEmpty(ids)){
                    whereSql .append( " and id in (").append(ids).append(")");
                }
            }
            if(DataUtil.idIsNotNull(condition.getId())){
                whereSql .append(" and id = ").append(condition.getId());
            }
            if(ObjectUtils.isNotEmpty(condition.getSysUserId())){
                whereSql .append(" and sysUserId = ").append(condition.getSysUserId());
            }
            if(ObjectUtils.isNotEmpty(condition.getIsQuestion())){
                whereSql .append(" and isQuestion = ").append(condition.getIsQuestion());
            }
            if(ObjectUtils.isNotEmpty(condition.getStatus())){
                whereSql .append(" and status =" ).append(condition.getStatus());
            }
            if(StringUtils.isNotEmpty(condition.getSubjectIds())){
                whereSql .append(StringUtils.getSubjectSql("subjectIds",condition.getSubjectIds()));
            }
            if(ObjectUtils.isNotEmpty(condition.getTeacherType()) && condition.getTeacherType().intValue()>0){
                whereSql .append(" and teacherType=").append(condition.getTeacherType());
            }
            if(StringUtils.isNotEmpty(condition.getTeacherName())){
                whereSql .append(" and teacherName like '%").append(condition.getTeacherName()).append("%'");
            }
            if(StringUtils.isNotEmpty(condition.getTeacherIdentity())){
                String teacherIdentity = StringUtils.subHeadTailString(condition.getTeacherIdentity(),",");
                if(StringUtils.isNotEmpty(teacherIdentity)){
                    whereSql .append( " and teacherIdentity like '%").append(teacherIdentity).append("%'");
                }
            }
            if (StringUtils.isNotEmpty(condition.getTeacherNames())) {
                String[] array = StringUtils.subHeadTailString(condition.getTeacherNames(), ",").split(",");
                StringJoiner nameJoiner = new StringJoiner(" or ");
                for (String n : array) {
                    nameJoiner.add(" ( teacherName like '%" + n + "%' )");
                }
                whereSql.append(" and (").append(nameJoiner).append(")");
            }
        }
        if(ObjectUtils.isNotEmpty(condition)&&ObjectUtils.isNotEmpty(condition.getIsQuestionOrder())){
            whereSql .append(" order by ").append( condition.getIsQuestionOrder()==1?" isQuestion desc,":"").append(" sort desc,createTime desc");
        }else {
            whereSql .append(" order by sort desc,createTime desc");
        }

        return whereSql.toString();
    }
    /**
     * 设置讲师的创建用户、关联的管理员数据
     * @param sysTeacher 讲列对象
     * @param createUser 是否设置创建人的数据，true设置，false不设置
     * @param sysUserData 是否设置关联管理的数据，true设置，false不设置
     * @return SysTeacher
     */
    private SysTeacher setSysTeacherSysUser(SysTeacher sysTeacher,boolean createUser,boolean sysUserData){
        if(ObjectUtils.isNotEmpty(sysTeacher)){
            List<SysTeacher> sysTeacherList = new ArrayList<>();
            sysTeacherList.add(sysTeacher);
            sysTeacherList = setSysTeacherSysUser(sysTeacherList,createUser,sysUserData);
            sysTeacher = sysTeacherList.get(0);
        }
        return sysTeacher;
    }
    /**
     * 设置讲师的创建用户、关联的管理员数据
     * @param sysTeacherList 讲列表
     * @param createUser 是否设置创建人的数据，true设置，false不设置
     * @param sysUserData 是否设置关联管理的数据，true设置，false不设置
     * @return List<SysTeacher>
     */
    private List<SysTeacher> setSysTeacherSysUser(List<SysTeacher> sysTeacherList,boolean createUser,boolean sysUserData){
        if(ObjectUtils.isNotEmpty(sysTeacherList)){
            String userIds = "";
            if(createUser){//获取创建人的ID串
                userIds = sysTeacherList.stream().filter(e->ObjectUtils.isNotEmpty(e.getCreateUserId())).filter(e->e.getCreateUserId().compareTo(new BigDecimal(0))>0).map(e->e.getCreateUserId().toString()).collect(Collectors.joining(","));
            }
            if(sysUserData){//获取关联管理员ID串
                String _userIds = sysTeacherList.stream().filter(e->ObjectUtils.isNotEmpty(e.getSysUserId())).filter(e->e.getSysUserId().compareTo(new BigDecimal(0))>0).map(e->e.getSysUserId().toString()).collect(Collectors.joining(","));
                if(StringUtils.isNotEmpty(_userIds)){
                    if(StringUtils.isNotEmpty(userIds)){
                        userIds = userIds+","+_userIds;
                    }else{
                        userIds = _userIds;
                    }
                }
            }
            if(ObjectUtils.isNotEmpty(userIds)){
                Map<BigDecimal,SysUser> sysUserMap = sysUserBiz.findSysUserByIds(userIds);
                if(ObjectUtils.isNotEmpty(sysUserMap)){
                    sysTeacherList.forEach(e->{
                        if(sysUserData){
                            SysUser sysUser = sysUserMap.get(e.getSysUserId());
                            if(ObjectUtils.isNotEmpty(sysUser)){
                                e.setSysUser(sysUser);
                            }
                        }
                        if(createUser){
                            SysUser sysUser = sysUserMap.get(e.getCreateUserId());
                            if(ObjectUtils.isNotEmpty(sysUser)){
                                e.setSysCreateUser(sysUser);
                            }
                        }
                    });
                }
            }
        }
        return sysTeacherList;
    }
    /**
     * 设置讲师列表的专业
     * @param sysTeacher 讲师对象
     * @param subjectData 是否设置专业数据，true设置，false不设置
     * @return List<SysTeacher>
     */
    private SysTeacher setSysTeacherSubject(SysTeacher sysTeacher, boolean subjectData){
        if(ObjectUtils.isNotEmpty(sysTeacher)){
            List<SysTeacher> sysTeacherList = new ArrayList<>();
            sysTeacherList.add(sysTeacher);
            sysTeacherList = this.setSysTeacherSubject(sysTeacherList,subjectData);
            sysTeacher = sysTeacherList.get(0);
        }
        return sysTeacher;
    }
    /**
     * 设置讲师列表的专业
     * @param sysTeacherList 讲师列表
     * @param subjectData 是否设置专业数据，true设置，false不设置
     * @return List<SysTeacher>
     */
    private List<SysTeacher> setSysTeacherSubject(List<SysTeacher> sysTeacherList, boolean subjectData){
        if(ObjectUtils.isNotEmpty(sysTeacherList) && subjectData){
            //得到所有的专业ID串
            String subjectIds = commonSetSubjectDataService.getSubjectIds(sysTeacherList);
            //获取专业Map
            Map<BigDecimal,SysSubject> subjectMap = sysSubjectBiz.findSubjectListByIds(subjectIds);
            if(ObjectUtils.isNotEmpty(subjectMap)){
                commonSetSubjectDataService.setSubjectData(subjectMap,sysTeacherList);
            }
        }
        return sysTeacherList;
    }

    /**
     * 设置讲师关联课程
     * @param sysTeacher 讲师列表
     * @param courseData 是否设置课程数据true是，false否
     * @return SysTeacher
     */
    public SysTeacher setSysTeacherCourse(SysTeacher sysTeacher,boolean courseData){
        this.setSysTeacherCourse(Arrays.asList(sysTeacher),courseData);
        return sysTeacher;
    }

    /**
     * 设置讲师关联课程
     * @param sysTeacherList 讲师列表
     * @param courseData 是否设置课程数据true是，false否
     * @return
     */
    private List<SysTeacher> setSysTeacherCourse(List<SysTeacher> sysTeacherList, boolean courseData){
        if(ObjectUtils.isNotEmpty(sysTeacherList) && courseData){
            String teacherIds = sysTeacherList.stream().map(e -> e.getId().toString()).collect(Collectors.joining(","));
            Map<String, Object> condition = new HashMap<>();
            condition.put("teacherIds", teacherIds);
            condition.put("status",1);
            condition.put("orderType",1);
            condition.put("type",1);
            condition.put("notExpire",true);
            condition.put("notCourseTypeKey", CourseType.COURSE_TYPE_PACKAGE.getKey());
            List<Map<String, Object>> courseList = courseService.findCourseList(condition, false, false, false,false);
            if(ObjectUtils.isNotEmpty(courseList)){
                for (SysTeacher teacher : sysTeacherList) {
                    for (Map<String, Object> course : courseList) {
                        if(((String)course.get("teacherIds")).contains(teacher.getId().toString())){
                            teacher.setCourseMap(course);
                            break;
                        }
                    }
                }
            }
        }
        return sysTeacherList;
    }

    public SysTeacher setSysTeacherQaType(SysTeacher sysTeacher,boolean qaTypeData){
        this.setSysTeacherQaType(Arrays.asList(sysTeacher),qaTypeData);
        return sysTeacher;
    }

    /**
     * 设置关联问答分类
     * @param sysTeacherList 讲师列表
     * @param qaTypeData 是否设置问答分类
     * @return
     */
    private List<SysTeacher> setSysTeacherQaType(List<SysTeacher> sysTeacherList, boolean qaTypeData){
        if(ObjectUtils.isNotEmpty(sysTeacherList) && qaTypeData){
            String qaTypeIds = sysTeacherList.stream().filter(e -> e.getIsQuestion() == 1).map(e -> e.getQaTypeId().toString()).collect(Collectors.joining(","));
            Map<String, Object> params = new HashMap<>();
            params.put("ids", qaTypeIds);
            List<Map<String, Object>> qaTypeList = qaTypeService.queryQaTypeList(params);
            if(ObjectUtils.isNotEmpty(qaTypeList)){
                for (SysTeacher sysTeacher : sysTeacherList) {
                    if(sysTeacher.getIsQuestion() == 1){
                        for (Map<String, Object> map : qaTypeList) {
                            if(sysTeacher.getQaTypeId().equals(BigDecimal.valueOf((Integer)map.get("id")))){
                                sysTeacher.setQaType(map);
                                break;
                            }
                        }
                    }
                }
            }
        }
        return sysTeacherList;
    }


    /**
     * 通过ID串获取讲师Map集合
     * @param ids 讲师ID
     * @return
     */
    public Map<BigDecimal,SysTeacher> findSysTeacherToMapBySimpleIds(String ids) {

        List<SysTeacher> sysTeacherList = this.find("id in ("+ids+")",null,this.getColumnName());
        if(ObjectUtils.isNotEmpty(sysTeacherList)){
            return sysTeacherList.stream().collect(Collectors.toMap(BaseEntity::getId, e->e));
        }
        return null;
    }

    private List<String> getColumnName(){
        return Arrays.asList("id","teacherName","subjectIds","sysUserId","imageJson","teacherType","isQuestion","qaTypeId","questionFee","separateInto","accountType","account","realName","sort","createUserId","courseNum","questionNum","userNum","status","createTime","updateTime");
    }
}
